
// AdminController.java
package org.example.data_work_demo1.controller;

import org.example.data_work_demo1.model.Admin;
import org.example.data_work_demo1.model.User;
import org.example.data_work_demo1.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    // 管理员登录 (POST请求示例)
    @PostMapping("/login")
    public Admin login(@RequestParam String username, @RequestParam String password) {
        return adminService.login(username, password);
    }

    // 添加管理员 (POST请求示例)
    @PostMapping
    public void addAdmin(@RequestBody Admin admin) {
        adminService.addAdmin(admin);
    }

    // 删除管理员 (DELETE请求示例)
    @DeleteMapping("/{adminId}")
    public void deleteAdmin(@PathVariable Integer adminId) {
        adminService.deleteAdmin(adminId);
    }

    // 更新管理员信息 (PUT请求示例)
    @PutMapping
    public void updateAdmin(@RequestBody Admin admin) {
        adminService.updateAdmin(admin);
    }

    // 获取所有用户 (GET请求示例)
    @GetMapping("/users")
    public List<User> getAllUsers() {
        return adminService.getUsers(); // 需要在AdminService中添加getUsers方法
    }
    // 添加用户 (POST请求示例)
    @PostMapping("/users")
    public void addUser(@RequestBody User user) {
        adminService.addUser(user);
    }
    // 删除用户 (DELETE请求示例)
    @DeleteMapping("/users/{userId}")
    public void deleteUser(@PathVariable Integer userId) {
        adminService.deleteUser(userId);
    }
    // 更新用户信息 (PUT请求示例)
    @PutMapping("/users")
    public void updateUser(@RequestBody User user) {
        adminService.updateUser(user);
    }
    //查询所有管理员
    @GetMapping("/admins")
    public List<Admin> getAllAdmins() {
        return adminService.getAllAdmins();
    }
}
